package com.hwh.bootdemoweb.Netty第六章;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestNettyFuture {
    public static void main(String[] args) throws Exception{
        NioEventLoopGroup group = new NioEventLoopGroup();

        EventLoop loop = group.next();

        Future<Integer> future = loop.submit(() -> {
            log.debug("执行计算");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 50;
        });

        log.debug("等待结果");
        log.debug("结果是:{}",future.get());
        //异步接受结果
        future.addListener((future1)->{
            log.debug("异步接收结果:{}",future1.getNow());
        });
    }
}
